package com.sykj.why.util;

/**
 * @program: why
 * @description: 数组操作工具类
 * @author: hqz
 * @create: 2018-09-18 16:48
 **/
public class ArrayTools {

    /**
     * long数组增加元素
     * @return
     */
    public static long[] add(long[] strs,long str){
        long[] arrays = new long[strs.length + 1];
        for (int i = 0;i < strs.length ; i++) {
            arrays[i] = strs[i];
        }
        arrays[strs.length] = str;
        return arrays;
    }

    /**
     * String数组增加元素
     * @return
     */
    public static String[] add(String[] strs,String str){
        String[] newStrs = new String[strs.length + 1];
        for (int i = 0;i < strs.length ; i++) {
            newStrs[i] = strs[i];
        }
        newStrs[strs.length] = str;
        return newStrs;
    }


    /**
     * String数组删除指定元素
     * @param strs
     * @param str
     * @return
     */
    public static String[] delete(String[] strs,String str){
        int resultLen = 0;
        String[] newStrs = new String[strs.length - 1];
        for (int i = 0;i < strs.length ; i++) {
            if (!strs[i].equals(str)) {
                newStrs[resultLen] = strs[i];
                resultLen++;
            }
        }
        return newStrs;
    }
}
